﻿using Brc_PaaS.Common.Model.Basic;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace Brc_PaaS.Common.Model.Exceptionless
{
    /// <summary>
    /// exceptionless创建项目返回的数据库模型
    /// </summary>
    public class EplCreateProjectResModel
    {
        #region 项目创建
        /// <summary>
        /// 项目Id
        /// </summary>
        public string id { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime created_utc { get; set; }
        /// <summary>
        /// 组织机构Id
        /// </summary>
        public string organization_id { get; set; }
        /// <summary>
        /// 组织机构名称
        /// </summary>
        public string organization_name { get; set; }
        /// <summary>
        /// 项目名称
        /// </summary>
        public string name { get; set; }
    }
    /// <summary>
    /// exceptionless创建项目请求模型
    /// </summary>
    public class EplCreateProjectReqModel
    {
        /// <summary>
        /// 组织机构Id
        /// </summary>
        public string organization_id { get; set; }
        /// <summary>
        /// 系统名称
        /// </summary>
        public string name { get; set; }
        /// <summary>
        /// 删除数据功能是否启用
        /// </summary>
        public bool delete_bot_data_enabled { get { return true; } }
    }
    #endregion

    #region 创建APIKEY
    /// <summary>
    /// exceptionless为项目创建apikey请求模型
    /// </summary>
    public class EplCreateApiKeyReqModel
    {
        /// <summary>
        /// 组织机构Id
        /// </summary>
        public string organization_id { get; set; }
        /// <summary>
        /// 项目Id
        /// </summary>
        public string project_id { get; set; }
        /// <summary>
        /// 默认项目Id
        /// </summary>
        public string default_project_id { get { return project_id; } }
        /// <summary>
        /// 作用域（client,server）
        /// </summary>
        public string[] scopes { get { return new string[] { }; } }
        /// <summary>
        /// 失效时间
        /// </summary>
        public string expires_utc { get { return DateTime.UtcNow.AddYears(10).ToString("s"); } }
        /// <summary>
        /// 备注
        /// </summary>
        public string notes { get; set; }

    }
    /// <summary>
    /// exceptionless创建apikey后返回的模型
    /// </summary>
    public class EplCreateApiKeyResModel
    {
        /// <summary>
        /// 组织机构Id
        /// </summary>
        public string organization_id { get; set; }
        /// <summary>
        /// 项目Id
        /// </summary>
        public string project_id { get; set; }
        /// <summary>
        /// APIKEY
        /// </summary>
        public string id { get; set; }
        /// <summary>
        /// 作用域（client,server）
        /// </summary>
        public string[] scopes { get; set; }
        /// <summary>
        /// 失效时间
        /// </summary>
        public DateTime expires_utc { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime created_utc { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string notes { get; set; }

    }

    #endregion

    #region 写异常
    /// <summary>
    /// exceptionless创建异常信息请求模型
    /// </summary>
    public class ElpCreateExceptionReqModel
    {
        /// <summary>
        /// 类型
        /// </summary>
        public string type { get { return "error"; } }
        /// <summary>
        /// 异常时间
        /// </summary>
        public string date { get { return DateTime.Now.ToString("s"); } }
        /// <summary>
        /// 异常信息
        /// </summary>
        public ElpExceptionModel simple_error { get; set; }
        /// <summary>
        /// 异常提交系统身份信息
        /// </summary>
        public ExceptionSystemModel user { get; set; }
        /// <summary>
        /// 异常自定义标签
        /// </summary>
        public string[] tags { get; set; }
        /// <summary>
        /// 项目Id
        /// </summary>
        public string projectid { get; set; }
    }
    /// <summary>
    /// 异常提交系统身份信息
    /// </summary>
    public class ExceptionSystemModel
    {
        /// <summary>
        /// 异常提交系统Id
        /// </summary>
        public string identity { get; set; }
        /// <summary>
        /// 异常提交系统名称
        /// </summary>
        public string name { get; set; }
    }
    /// <summary>
    /// 异常模型
    /// </summary>
    public class ElpExceptionModel
    {
        /// <summary>
        /// 异常消息
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// 异常类型
        /// </summary>
        public string type { get; set; }
        /// <summary>
        /// 堆栈
        /// </summary>
        public string stack_trace { get; set; }
    }

    #endregion


    #region 写日志
    /// <summary>
    /// exception日志记录请求模型
    /// </summary>
    public class ElpCreateLogReqModel
    {
        /// <summary>
        /// 类型
        /// </summary>
        public string type { get { return "log"; } }
        /// <summary>
        /// 日志记录时间
        /// </summary>
        public string date { get { return DateTime.Now.ToString("s"); } }
        /// <summary>
        /// 日志信息
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// 日志类型
        /// </summary>
        public string level { get; set; }
        /// <summary>
        /// 日志提交系统身份信息
        /// </summary>
        public ExceptionSystemModel user { get; set; }
        /// <summary>
        /// 日志自定义标签
        /// </summary>
        public string[] tags { get; set; }
        /// <summary>
        /// 项目Id
        /// </summary>
        public string projectid { get; set; }
    }

    #endregion

    #region 查询异常/日志
    /// <summary>
    /// exceptionless查询日志请求模型
    /// </summary>
    public class EplSearchEventReqModel
    {
        /// <summary>
        /// 查询类型（log:日志，error:异常）
        /// </summary>
        [Required(ErrorMessage = "查询类型不能为空")]
        public string type { get; set; }
        /// <summary>
        /// 自定义标签
        /// </summary>        
        public string tags { get; set; }
        /// <summary>
        /// 日志类型（仅限查询日志使用，异常不用）
        /// </summary>
        public string level { get; set; }

        /// <summary>
        /// 返回数据格式，定义为summary表示返回精简格式，不设置则返回全部数据
        /// </summary>
        public string mode { get { return "summary"; } }
        /// <summary>
        /// 时间偏移量
        /// </summary>
        public string offset { get { return "480m"; } }
        /// <summary>
        /// 当前页
        /// </summary>
        public int page { get; set; }
        /// <summary>
        /// 每页限制数
        /// </summary>
        public int limit { get; set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? starttime { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? endtime { get; set; }
        /// <summary>
        /// 项目Id
        /// </summary>
        [Required(ErrorMessage = "项目Id不能为空")]
        public string projectid { get; set; }
    }
    /// <summary>
    /// 日志查询列表返回模型
    /// </summary>
    public class EplSearchEventResModel
    {
        public string Id { get; set; }
        public string Date { get; set; }
        public EventBodySummaryModel data { get; set; }
    }
    public class EventBodySummaryModel
    {
        /// <summary>
        /// 日志消息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 提交日志系统Id
        /// </summary>
        public string Identity { get; set; }
        /// <summary>
        /// 提交日志系统名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 异常类型
        /// </summary>
        public string Type { get; set; }
        /// <summary>
        /// 异常类型全名
        /// </summary>
        public string TypeFullName { get; set; }
        /// <summary>
        /// 日志源
        /// </summary>
        public string Source { get; set; }
        /// <summary>
        /// 日志类型
        /// </summary>
        public string Level { get; set; }
    }

    /// <summary>
    /// 异常查询详情返回模型
    /// </summary>
    public class EplSearchExceptionDetailModel
    {
        public ExceptionDetailStackDataModel data { get; set; }
    }
    public class ExceptionDetailStackDataModel
    {
        public ExceptionSystemModel user { get; set; }
        public ElpExceptionModel simple_error { get; set; }
    }
    #endregion

    #region 登录信息
    public class EplLoginModel
    {
        public string AppKey { get; set; }

        [JsonProperty("email")]
        public string Email { get; set; }
        [JsonProperty("password")]
        public string Password { get; set; }
    }

    public class TokenModel
    {
        public string Token { get; set; }
    }
    #endregion
}
